<template>
    <div class="file" @dblclick="open" @contextmenu="contextmenu">
        <div style="width: 50px;margin: 0 auto">
            <img :src="'sys/file/icon?filePath='+file.filePath" width="50" height="50">
        </div>
        <div class="text" style="width: 100%;">
            {{ file.fileName }}
        </div>
    </div>
</template>

<script>
    import sys from "../../../../js/windowManager"


    export default {
        name: "file",
        props: {
            file: {
                type: Object,
                required: true,
            }
        },
        methods: {
            open() {
                sys.openFile(this.file.filePath)
            },
            contextmenu(e) {
                console.log("右键")
                sys.setFileClipboardFiles([this.file.filePath])
                this.$contentMenu.open(e, [
                    {
                        label: "新建文件夹",
                        enable: false,
                    },
                    {
                        label: "刷新",
                        enable: false,
                    },
                    {},
                    {
                        label: "复制",
                        enable: true,
                        call: () => {
                            console.log("复制：", this.file)
                        }
                    },
                    {
                        label: "剪切",
                        enable: true,
                        call: () => {
                            console.log("剪切：", this.file)
                        }
                    },
                    {
                        label: "删除",
                        enable: () => {
                            return sys.getFileClipboardFiles().length > 0
                        },
                        call: () => {
                            // console.log("删除：", this.file)
                            this.deleteFile(sys.getFileClipboardFiles())
                        }
                    },
                    {
                        label: "粘贴",
                        enable: false
                    },
                ])
            },
            deleteFile(files) {
                this.$axios.delete("/desktop/files", {data: files}).then(res => {
                    console.log(res)
                    // this.getDeskTopFiles();
                    if (res.data.status == 200) {
                        this.$emit('refresh')
                    } else {
                        console.log("open")

                        //打开删除tool
                        let win = sys.creatWindow({
                            files: files,
                            url: "/fileCopy.html",
                            changeSize:false,
                            param: {
                                taskId: res.data.data,
                                type:"删除"
                            },
                            size: {
                                width: 400,
                                height: 200
                            }
                        })
                        console.log(win)
                    }
                })
                console.log(this)
            },
        }
    }
</script>

<style scoped>
    .file {
        width: 60px;
        height: 80px;
        /*background-color: silver;*/
    }

    .file:hover {
        cursor: pointer;
        background-color: rgba(239, 239, 239, 0.5);
    }

    .text {
        text-align: center;
        word-wrap: break-word;
        overflow: hidden;
        height: 30px;
        line-height: 15px;
    }
</style>